package com.lsl;

import java.util.concurrent.CountDownLatch;

public class ChangeText implements ToPrint {
    private String str;

    public void add() {

    }

    public static String formatCurrency(double num) {
        ChangeText changeText = new ChangeText();
        changeText.str = num + "";
        int index = changeText.str.indexOf(".");
        char[] c = changeText.str.toCharArray();
        char[] b = new char[c.length + 1];
        for (int i = c.length - 1; i > 0; i--) {
            index -= 3;
            if(i==index){
            int count = c.length;
            for (int j = c.length - 1; j > 0; j--) {
                if (j == index) {
                    b[count - 1] = ',';
                }
                b[count] = c[j];
                count--;
            }
            }

            c = b;
        }
        changeText.str = String.valueOf(c);
        return changeText.str;


    }

    public static String camelToSnake(String str) {
        ChangeText changeText = new ChangeText();
        changeText.setStr(str);
        char[] c = changeText.str.toCharArray();
        int index = -1;
        for (int i = 0; i < c.length; i++) {
            if (c[i] < 97) {
                c[i] += 32;
                index = i;
                int count = 0;
                char[] b = new char[c.length + 1];
                for (int j = 0; j < c.length; j++) {
                    if (j == index) {
                        b[count] = '_';
                        count += 1;
                    }
                    b[count] = c[j];
                    count++;
                }
                c = b;
            }
        }
        changeText.str = String.valueOf(c);
        return changeText.str;

    }

    public static String snakeToCamel(String str) {
        ChangeText changeText = new ChangeText();
        changeText.setStr(str);
        String[] strArr = changeText.str.split("_");

        for (int i = 0; i < strArr.length; i++) {

            char[] c = strArr[i].toCharArray();
            c[0] -= 32;
            strArr[i] = String.valueOf(c);
        }
        String resualt = "";
        for (int i = 0; i < strArr.length; i++) {
            resualt += strArr[i];
        }
        changeText.str = resualt;
        return changeText.getStr();
    }


    public void toPrint() {
        System.out.println(getStr());
    }

    public String getStr() {
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }
}
